<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <link rel="stylesheet" href="./style.css" />
    <title>06_CSS反向悬停</title>
  </head>
  <body>
    <div class="switch">
      <input type="checkbox" name="toggle" id="toggle" />
      <label for="toggle" class="toggleLabel"></label>
    </div>
    <ul>
      <li>
        <a href="#">
          <svg
            xmlns="http://www.w3.org/2000/svg"
            xmlns:xlink="http://www.w3.org/1999/xlink"
            version="1.1"
            width="20px"
            height="20px"
            viewBox="0 0 400 400"
          >
            <image id="image0" width="400" height="400" href="../assets/icons/xinlang.png" />
          </svg>
          微博
        </a>
      </li>
      <li>
        <a href="#">
          <svg
            xmlns="http://www.w3.org/2000/svg"
            xmlns:xlink="http://www.w3.org/1999/xlink"
            version="1.1"
            width="20px"
            height="20px"
            viewBox="0 0 400 400"
          >
            <image id="image0" width="400" height="400" href="../assets/icons/bilibili.png" />
          </svg>
          BiLibili
        </a>
      </li>
      <li>
        <a href="#">
          <svg
            xmlns="http://www.w3.org/2000/svg"
            xmlns:xlink="http://www.w3.org/1999/xlink"
            version="1.1"
            width="20px"
            height="20px"
            viewBox="0 0 400 400"
          >
            <image id="image0" width="400" height="400" href="../assets/icons/toutiao.png" />
          </svg>
          今日头条
        </a>
      </li>
      <li>
        <a href="#">
          <svg
            xmlns="http://www.w3.org/2000/svg"
            xmlns:xlink="http://www.w3.org/1999/xlink"
            version="1.1"
            width="20px"
            height="20px"
            viewBox="0 0 400 400"
          >
            <image id="image0" width="400" height="400" href="../assets/icons/boos.png" />
          </svg>
          Boss直聘
        </a>
      </li>
      <li>
        <a href="#">
          <svg
            xmlns="http://www.w3.org/2000/svg"
            xmlns:xlink="http://www.w3.org/1999/xlink"
            version="1.1"
            width="20px"
            height="20px"
            viewBox="0 0 400 400"
          >
            <image width="400" height="400" href="../assets/icons/douyin.png" />
          </svg>
          抖音
        </a>
      </li>
    </ul>
    <script>
      const input = document.querySelector('#toggle')
      const text = document.querySelectorAll('ul>li>a')
      const body = document.body
      input.addEventListener('change', function () {
        if (input.checked) {
          body.className = 'dark'
          text.forEach(item => {
            item.className = 'dark'
          })
        } else {
          body.className = 'light'
          text.forEach(item => {
            item.className = 'light'
          })
        }
      })
    </script>
    <script>
      // 判断是否为夜间模式
      const isDark = window.matchMedia('(prefers-color-scheme: dark)').matches
      if (isDark) {
        input.checked = true
      }
    </script>
  </body>
</html>
